# /mnt/nas/shengjie/qdrant_data/qwenvl3_data/qwenvl3_cloth_data2600.csv
# INSERT_YOUR_CODE
import pandas as pd
import json

csv_file_path = "/mnt/nas/shengjie/qdrant_data/qwenvl3_data/qwenvl3_cloth_data2600.csv"
df = pd.read_csv(csv_file_path)

results = []
materials = set()
patterns = set()
for idx, row in df.iterrows():
    desc_json = row.get('desc_json', None)

    if not isinstance(desc_json, str):
        continue
    try:
        desc_dict = json.loads(desc_json)
    except Exception:
        continue

    # 查找材质
    try:
        materials_info = desc_dict.get('material', {}).get('composition', [])
        if isinstance(materials_info, list):
            for m in materials_info:
                if isinstance(m, dict) and 'material' in m:
                    mat = m['material']
                    if isinstance(mat, str):
                        materials.add(mat.strip().lower())
    except Exception:
        pass
    # 查找pattern
    try:
        patterns_info = desc_dict.get('design', {}).get('color', {}).get('pattern',[])
        if isinstance(patterns_info, list):
            for p in patterns_info:
                if isinstance(p, str):
                    patterns.add(p.strip().lower())
    except Exception:
        pass


    # 查找设计分类主类
    category_main = None
    try:
        category_main = desc_dict.get('design', {}).get('category', {}).get('main', None)
    except Exception:
        pass

    if category_main != 'outerwear':
        continue

    # 查找pockets下所有count==-1
    pockets = desc_dict.get('design', {}).get('pockets', None)
    pockets_with_neg1 = False
    if isinstance(pockets, list):
        for p in pockets:
            if isinstance(p, dict):
                if p.get('count', None) == -1 or p.get('count', None) == "-1":
                    pockets_with_neg1 = True
                    break
    else:
        break

    if pockets_with_neg1:
        results.append({
            "img_path": row.get("img_path", ""),
            "desc_json": desc_json
        })

# 输出找到的样本数和前几个样本
print(f"Total samples where design.category.main == 'outerwear' and some design.pockets.count == -1: {len(results)}")
# for r in results[:5]:
#     print(r["img_path"], r["desc_json"])

print("Materials for this sample:", materials)
print("Patterns for this sample:", patterns)

'''
Materials for this sample: 
{'linen', 'cotton', 'corduroy', 'shearling', 'fur', 'suede', 'acrylic', 
'wool', 'denim', 'nylon', 'leather', 'polyester', 'polyurethane', 
'sequin',   'knit',  'velvet', 'denim_cotton', 'faux_fur', 'knit_fabric'}

这件样衣所用材质包括：
{'亚麻',   '棉',      '灯芯绒',    '羊毛皮',  '真皮草','麂皮', '腈纶', 
'羊毛', '牛仔布', '尼龙',   '皮革',     '涤纶',       '聚氨酯', 
'亮片面料', '针织面料', '天鹅绒', '棉质牛仔布', '人造毛皮', '针织布'}


Patterns for this sample: 
{'distressed', 'fruit', 'zigzag', 'tie_dye', 'gradient', 'camouflage', 'damask', 'embroidered_lace', 
{'做旧破洞',   '水果图案', '锯齿形', '扎染',   '渐变',       '迷彩',      '花缎纹',   '刺绣蕾丝', 
'gg monogram', 'embroidered', 'splatter', 'letter_print', 'marble', 'animal_print', 'figurative', 
'GG字母组合',      '刺绣',      '泼墨',       '字母印花',   '大理石纹',  '动物纹',      '人像图案', 
'lacy', 'palm_leaf', 'graphic', 'striped', 'baroque', 'tree_branch_print', 'tweed', 'crocodile', 
'蕾丝',   '棕榈叶',  '图形印花', '条纹',    '巴洛克风格', '树枝印花',          '粗花呢', '鳄鱼纹', 
'clover', 'checkered', 'embroidered_floral', 'paisley', 'star', 'polka_dot', 'custom_print', 'embossed', 
'三叶草',   '方格',       '花卉刺绣',        '佩斯利涡纹',  '星星',   '波点',     '定制印花',      '压花', 
'embroidered_butterflies', 'hounds-tooth', 'feather', 'insect', 'patchwork', 'abstract', 'geometric', 
'蝴蝶刺绣',                     '犬牙纹',     '羽毛',     '昆虫',     '拼布',    '抽象',     '几何', 
'bandana',     'monogram', 'binary_code', 'corduroy', 'ocean_life_print', 'illustrative', 'mushroom', 
'班丹纳方巾纹', '字母组合', '二进制代码',     '灯芯绒',   '海洋生物印花',       '插画风',       '蘑菇', 
'embellished', 'butterfly_print', 'logo',   'angelic', 'text_print', 'wave', 'chain', 'digital_print', 
'装饰',           '蝴蝶印花',      '品牌标识', '天使',      '文字印花',  '波浪', '链条',    '数码印花', 
'spray_paint', 'cracked_glass', 'embossed_logo', 'sequined', 'sparkle', 'speckled', 'print', 'lace', 
'喷漆',          '裂纹玻璃',        '压花标识',      '亮片',     '闪亮',     '斑点',    '印花',  '蕾丝', 
'solid', 'beaded', 'knit', 'dripping', 'floral', 'script', 'dot', 'textured', 'herringbone', 'heart', 
'纯色',    '串珠',  '针织',   '滴墨',     '花卉',   '手写体', '圆点', '纹理',       '人字纹',     '心形', 
'star_print', 'quilted', 'bow', 'pleated', 'hole_pattern'}
'星星印花',     '绗缝',  '蝴蝶结', '百褶',     '孔洞图案'}
这件样衣的图案/纹理包括：
'''
